package com.openxt.nbzj.call;

import android.content.Context;

import com.openxt.nbzj.model.RemotingModel;
import com.openxt.nbzj.remoting.ClientEx;
import com.openxt.nbzj.remoting.RemotingEx;
import com.openxt.nbzj.util.SystemUtil;

import com.alibaba.fastjson.JSONObject;
import qs.openxt.libs.util.ActivityUtil;
import qs.openxt.libs.util.StringUtil;

/**
 * Created by 颖杰_2 on 2016-07-28.
 * 3.4	页面访问量统计
 */
public class AccessStatisticsManager implements RemotingEx.OnActionListener {

    private static AccessStatisticsManager manager = null;
    private RemotingModel remotingModel = null;

    protected AccessStatisticsManager(){
    }

    public static AccessStatisticsManager instance(){
        if( manager == null )
            manager = new AccessStatisticsManager();
        return manager;
    }

    public void start(Context context, String PageMark, boolean IsNative){
        if(StringUtil.isNull(PageMark))
            return;
        if(!ActivityUtil.isNetworkAvailable(context))
            return;
        JSONObject param = SystemUtil.getDevice(context);
        if(param == null)
            return;
        try {
            remotingModel = new RemotingModel(context);
            param.put("PageMark", PageMark);
            param.put("IsNative", IsNative);
            if(!RemotingModel.isLogin())
                param.put("CustomerId", ClientEx.CUSTOMERID);
            remotingModel.doAccessStatisticsCall(this, false, param);
        }catch (Exception e){

        }
    }

    @Override
    public void onActionCompleted(String reVal, String actionName) {

    }

    @Override
    public void onActionFailed(String errorVal, String actionName) {

    }
}
